package com.huanglj.taobaounion.ui.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.huanglj.taobaounion.R;
import com.huanglj.taobaounion.model.domain.OnSellResult;
import com.huanglj.taobaounion.utils.UrlUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OnSellAdapter extends RecyclerView.Adapter<OnSellAdapter.InnerHolder> {

    private static final String TAG = "OnSellAdapter";
    List<OnSellResult.DataBean.TbkDgOptimusMaterialResponseBean.ResultListBean.MapDataBean> mData = new ArrayList<>();
    @NonNull
    @Override
    public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_on_sell_list, parent, false);
        return new InnerHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull InnerHolder holder, int position) {
        holder.setData(mData.get(position));
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public void setData(List<OnSellResult.DataBean.TbkDgOptimusMaterialResponseBean.ResultListBean.MapDataBean> map_data) {
        mData.clear();
        mData.addAll(map_data);
        notifyDataSetChanged();
    }

    public class InnerHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.on_sell_goods_cover)
        ImageView mGoodCover;
        @BindView(R.id.on_sell_list_title)
        TextView mTextTitle;
        @BindView(R.id.on_sell_origin_prise)
        TextView originPrise;
        @BindView(R.id.on_sell_result_prise)
        TextView resultPrise;
        public InnerHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }

        public void setData(OnSellResult.DataBean.TbkDgOptimusMaterialResponseBean.ResultListBean.MapDataBean dataBean) {
            String coverPath = UrlUtils.getCoverPath(dataBean.getPict_url(), 400);
            Glide.with(itemView.getContext()).load(coverPath).into(mGoodCover);
            mTextTitle.setText(dataBean.getTitle());
        }
    }
}
